<template>
  <div class="divBox">
    <el-card class="normal-page" :body-style="{ padding: '0px 20px 50px 20px' }">
      <formBox
        :total="total"
        :info="info"
        :type="`module`"
        :keyName="keyName"
        @getInfo="getInfo"
        @getList="getList"
        @confirmData="confirmData"
        @addData="addData"
        @handleDelete="handleDelete"
        @handleDropdown="handleDropdown"
      ></formBox>
      <!-- 表格数据 -->
      <div
        class="table-box mt10 non-resize-el-table"
        v-if="info.showField && info.showField.length > 0"
        v-loading="loading"
      >
      <!--  highlight-current-row @current-change="handleCurrentChange" -->
        <el-table
          ref="table"
          :data="tableData"
          style="width: 100%"
          :max-height="tableHeight"
          @selection-change="handleSelectionChange"
          @row-click="handleRowClick"
          @row-dblclick="handleRowDoubleClick"
          row-key="id"
          border
           highlight-current-row @current-change="handleCurrentChange"
          :row-class-name="tableRowClassName"
          
        >
          <el-table-column type="selection" min-width="55" show-overflow-tooltip> </el-table-column>
          <!-- dengshunbo width 删除了image   [
                'input_percentage',
                'tag',
                'textarea',
                'date_picker',
                'date_time_picker',
                'cascader',
                'cascader_address'
              ].includes(item.form_value)
                ? 200
                : ''-->
          <el-table-column
            v-for="(item, index) in info.showField"
            :prop="item.field_name_en"
            :label="item.field_name"
            :key="index"
            min-width="110"
            :width="tabelWidth(item)"
          >
          <!--  @click.stop="lookViewer(val.url, val.name)" -->
            <template slot-scope="scope">
              <div v-if="item.form_value === 'image'" class="img-box">
                <img
                  v-for="(val, index) in scope.row[item.field_name_en]"
                  :key="index"
                  :src="val.url"
                  alt=""
                  class="img"
                />
                <span v-if="!scope.row[item.field_name_en] || scope.row[item.field_name_en].length == 0">--</span>
              </div>
              <div v-else-if="item.form_value === 'input_percentage'">
                <el-progress
                  :percentage="scope.row[item.field_name_en] ? scope.row[item.field_name_en] : 0"
                ></el-progress>
              </div>
              <div v-else-if="item.form_value === 'tag'">
                <el-popover
                  v-if="scope.row[item.field_name_en] && scope.row[item.field_name_en].length > 2"
                  placement="top-start"
                  trigger="hover"
                >
                  <template>
                    <div class="flex_box">
                      <div class="tips" v-for="(val, index) in scope.row[item.field_name_en]" :key="index">
                        <el-tag size="small">
                          {{ val }}
                        </el-tag>
                      </div>
                    </div>
                  </template>
                  <div slot="reference">
                    <div class="flex_box">
                      <div class="tips" v-for="(val, index) in scope.row[item.field_name_en]" :key="index">
                        <el-tag size="small" v-if="index < 2">
                          {{ val }}
                        </el-tag>
                      </div>
                      <el-tag
                        v-if="scope.row[item.field_name_en] && scope.row[item.field_name_en].length > 2"
                        size="small"
                        >...</el-tag
                      >
                    </div>
                  </div>
                </el-popover>
                <template v-else>
                  <div class="flex_box">
                    <div class="tips" v-for="(val, index) in scope.row[item.field_name_en]" :key="index">
                      <el-tag size="small" v-if="index < 2">
                        {{ val }}
                      </el-tag>
                    </div>
                    <el-tag
                      v-if="scope.row[item.field_name_en] && scope.row[item.field_name_en].length > 2"
                      size="small"
                      >...</el-tag
                    >
                  </div>
                </template>
                <span v-if="!scope.row[item.field_name_en] || scope.row[item.field_name_en].length == 0">--</span>
              </div>
              <div v-else-if="item.form_value === 'switch'">
                
                <el-switch :width="50"
                  disabled
                  v-model="scope.row[item.field_name_en]"
                  :active-value="1"
                  :inactive-value="0"
                  active-color="#47cb89"
                  :active-text="handlerSwitch(item.field_name_en, 1)"
                  :inactive-text="handlerSwitch(item.field_name_en, 0)"
                >
                </el-switch>
              </div>
          
              <div v-else-if="item.form_value === 'textarea'">

                <el-popover placement="top-start" width="350" trigger="hover" :content="scope.row[item.field_name_en]">
                  <div
                    class="over-text"
                    slot="reference"
                    v-if="scope.row[item.field_name_en] && scope.row[item.field_name_en].length > 11"
                  >
                    <span v-if="item.field_name_en == 'sunhaoshezhibili'">
                          <label v-for="(itemab, indexab) in JSON.parse(scope.row[item.field_name_en])" :key="indexab">
                             <label v-if="itemab.value2">
                               {{ itemab.value2 }}:{{ itemab.value3 }},
                             </label>
                          </label>
                    </span>
                    <span v-else>
                      {{ scope.row[item.field_name_en] }}
                    </span>
                  </div>
                </el-popover>
                <span v-if="scope.row[item.field_name_en] && scope.row[item.field_name_en].length <= 11">
                AA  {{ scope.row[item.field_name_en] }}
                </span>
                <span v-if="!scope.row[item.field_name_en]">--</span>
              </div>
              <div v-else-if="['input_number', 'input_float', 'input_price'].includes(item.form_value)">
                {{ scope.row[item.field_name_en] }}
              </div>
              <div v-else class="flex-center">
                <!-- start dengshunbo 去掉click @click.stop="checkRow(scope.row)" -->
                <span
                  v-if="item.field_name_en == info.crudInfo.main_field_name"
                  class="color-doc pointer"
                  
                >
                <!-- ened -->
                  <!-- dengshunbo 2024-12-27改 -->
                  <span v-if="getValue(scope.row[item.field_name_en]) == 'image'">
                    <img :src="loasturl + scope.row[item.field_name_en]" alt="" class="img"/>
                  </span>
                  <span v-else>
                       <span v-if="item.field_name_en=='sunhao'">
                          
                          <span v-if="scope.row[item.field_name_en]">
                            <span v-for="(itemva, indexva) in JSON.parse(scope.row[item.field_name_en])">
                               <span v-if="itemva.value3">
                                {{itemva.value2}}:{{ itemva.value3 }},
                               </span>
                            </span>
                          </span>
                          <span v-else>--</span>
                       </span>
                       <span v-else>
                        {{ getValue(scope.row[item.field_name_en], item.form_value) }}
                       </span>
                  
                  </span>
                  <!-- end -->
                  <span class="share-tag" v-if="scope.row.is_share"> 共享 </span></span
                >

                <!-- 多选 -->
                <div v-else-if="item.form_value == 'checkbox'">
                  <div
                    v-for="(val, index) in scope.row[item.field_name_en]"
                    class="dictionaries-tag over-text mr10"
                    :style="{
                      color: val.color ? val.color : '#1890ff',
                      background: val.color ? getColorFn(val.color, '0.1') : getColorFn('#1890ff', '0.1')
                    }"
                  >
                   {{ val.name }}
                  </div>
                  <div v-if="scope.row[item.field_name_en].length == 0">--</div>
                </div>

                <!-- 关联字典颜色 -->
                <div
                  v-else-if="
                    scope.row[item.field_name_en] &&
                    Object.prototype.hasOwnProperty.call(scope.row[item.field_name_en], 'color')
                  "
                  class="dictionaries-tag over-text"
                  :style="{
                    color: scope.row[item.field_name_en].color ? scope.row[item.field_name_en].color : '#1890ff',
                    background: scope.row[item.field_name_en].color
                      ? getColorFn(scope.row[item.field_name_en].color, '0.1')
                      : getColorFn('#1890ff', '0.1')
                  }"
                >
                  {{ scope.row[item.field_name_en].name }}
                </div>
                <span v-else> 
                  <!-- dengshunbo 2025-3-13 -->
                    
                    <span v-if="item.field_name_en == 'shouquanmenjinzu'">
                       {{ handlerFiltermjzid(scope.row[item.field_name_en]) }}
                    </span>
                    <span v-else-if="item.field_name_en == 'yaoqingmenjinzu'">
                       {{ handlerFiltermjz(scope.row[item.field_name_en]) }}
                    </span>
                    <span v-else-if="item.field_name_en == 'shouquanerweima' || item.field_name_en == 'tikongshouquanerweima'" :title="scope.row[item.field_name_en]">
                      {{ getValueStr(scope.row[item.field_name_en]) }}
                    </span>
                    <span v-else>
                      <span v-if="getValue(scope.row[item.field_name_en]) == 'image'">
                          <img :src="loasturl + scope.row[item.field_name_en]" alt="" class="img"/>
                      </span>
                      <span v-else>
                          {{ getValue(scope.row[item.field_name_en], item.form_value) }}
                      </span>
                    </span>
                </span>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="address" label="操作" fixed="right" width="160" align="center" v-if="handlerFilterAction(keyName)">
            <template slot-scope="scope">
              <el-button type="text" @click.stop="checkRow(scope.row)">查看</el-button>
              <!-- dengshunbo 2025-3-10 1.9版本编辑被隐藏 -->
              <el-button type="text" @click.stop="editRow(scope.row, 2)">编辑</el-button>
              <el-button type="text" class="mr10" @click.stop="deleteRow(scope.row)">删除</el-button>
              <!-- end -->
               <!-- 注释隐藏 -->
              <!-- <span @click.stop="">
                  <el-dropdown>
                    <span class="el-dropdown-link el-button--text el-button"> 更多 <i class="el-icon-arrow-down" /></span>
                    <el-dropdown-menu>
                      <el-dropdown-item @click.native="openShare(scope.row)"> 共享协作 </el-dropdown-item>
                      <el-dropdown-item v-if="scope.row.is_share" @click.native="cancelShare(scope.row)">
                        取消协作
                      </el-dropdown-item>
                      <el-dropdown-item @click.native="handleDropdown('transfer', scope.row)">
                        移交负责人
                      </el-dropdown-item>
                      <el-dropdown-item @click.native="deleteRow(scope.row)">删除</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
              </span> -->
            </template>
          </el-table-column>
        </el-table>
        <!-- class="page-fixed" -->
        <div class="page-fixed">
          <el-pagination
            :page-size="where.limit"
            :current-page="where.page"
            :page-sizes="[15, 20, 30]"
            layout="total,sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="pageChange"
          />
        </div>
      </div>
      <div v-else>
        <default-page :index="18" />
      </div>
    </el-card>

    <!-- 表格多选批量操作 -->
    <BatchActionBar
      :listCount="tableData.length"
      :selectCount="multipleSelection.length"
      @change="handleBottomBatchSelectChange"
      @delete="handleDelete"
      @share="handleBatchShareData"
      @transfer="handleBatchTransferData"
    />

    <!-- 拖拽导入 -->
    <dragUpload ref="dragUpload" @getList="getList"></dragUpload>
    <image-viewer ref="imageViewer" :src-list="srcList"></image-viewer>
    <!-- 新增 -->
    <add-drawer v-if="addDrawerShow" ref="addDrawer" :keyName="keyName" @getList="getList"></add-drawer>

    <!-- dengshunbo -->
    <sunhaoIndex ref="addsunhao" v-if="addDrawerShowsunhao" :status="2" @getList="getList"></sunhaoIndex>
    <!-- 新增(新) -->
    <add-drawernew v-if="addDrawerShownew" ref="addDrawernew" :keyName="keyName" @getList="getList"></add-drawernew>
    <!-- 查看 -->
    <check-drawer
      v-if="checkDrawerShow"
      ref="checkDrawer"
      :keyName="keyName"
      :info="info"
      @getList="getList"
      @getInfo="getInfo"
    ></check-drawer>
    <!-- 查看 -->
    <check-new-details
      v-if="checkNewDetailsShow"
      ref="checkNewDetails"
      :keyName="keyName"
      :info="info"
      @getList="getList"
      @getInfo="getInfo"
    ></check-new-details>
    <!-- 移交 -->
    <oa-dialog
      ref="oaDialog"
      :formConfig="formConfig"
      :formDataInit="formDataInit"
      :formRules="formRules"
      :fromData="fromData"
      @submit="submit"
    ></oa-dialog>
    <!-- 数据共享列表 -->
    <share ref="share"></share>
    <!-- 邀请填写弹窗 -->
    <fillInDialog ref="fillInDialog"></fillInDialog>
    <!-- 邀请记录 -->
    <fillIn ref="fillIn"></fillIn>
  </div>
</template>
<script>
import ApiUrl from '@/api/apiUrls' // dengshunbo 2024-12-27新增
import { getColor } from '@/utils/format'
import defaultPage from '@/components/common/defaultPage'
import Commnt from '@/components/develop/commonData'
import formBox from './components/formBox'
import dragUpload from './components/dragUpload'
import checkDrawer from './components/checkDrawer'
import checkNewDetails from './components/checknewDetails'
import fillInDialog from './components/fillInDialog'
import addDrawer from './components/addDrawer'
import addDrawernew from './components/addDrawernew'
import sunhaoIndex from '@/components/sunhaoForm/index.vue'
import fillIn from './components/fillIn'
import share from '@/views/develop/module/components/share'
import oaDialog from '@/components/form-common/dialog-form'
import imageViewer from '@/components/common/imageViewer'
import {
  crudModuleListApi,
  crudModuleInfoApi,
  crudModuleDelApi,
  crudModuleFindApi,
  crudModuleBatchDelApi,
  moduleTransferApi,
  moduleShareApi,
  delCancelShareApi,
  putUpdateFieldApi,
  crudModuleUpdateApi
} from '@/api/develop'
import BatchActionBar from './components/batchActionBar.vue'
import batchActionHandler from './mixins/batchActionHandler'

export default {
  components: {
    formBox,
    addDrawer,
    addDrawernew,
    checkDrawer,
    checkNewDetails,
    imageViewer,
    dragUpload,
    oaDialog,
    share,
    fillInDialog,
    fillIn,
    BatchActionBar,
    defaultPage,
    sunhaoIndex
  },
  mixins: [batchActionHandler],
  data() {
    return {
      loading: false,
      checkNewDetailsShow: false,
      addDrawerShow: false,
      addDrawerShownew: false,
      addDrawerShowsunhao: false,
      checkDrawerShow: false,
      dropdownType: '',
      formConfig: [],
      formDataInit: {
        user_id: ''
      },
      formRules: {
        user_id: [{ required: true, message: '请选择人员', trigger: 'blur' }],
        user_ids: [{ required: true, message: '请选择人员', trigger: 'blur' }],
        role_type: [{ required: true, message: '请选择共享权限', trigger: 'blur' }]
      },
      fromData: {
        width: '600px',
        title: '选择接手人',
        btnText: '确定',
        labelWidth: '100px',
        type: ''
      },

      keyName: '',
      info: {},
      total: 0,
      srcList: [],
      tableData: [],
      rowData: {},
      where: {
        page: 1,
        limit: 15
      },
      multipleSelection: [],
      searchTypeOptions: Commnt.searchTypeOptions,

      // dengshunbo 2024-12-27新增
      loasturl: ApiUrl,  
      externalContent: '',
      tokenval: '',
      screenUrl:'https://erp.langsenkeji.com/echartScreen/index.html',
      screeniframUrl: '',
      iframeShow: false,
      menjinData: [],
      currentRow: null,
      tableRowObject: null,
      currentRowIndex: null,
      userinfoObj: {},
      searchObj:{
          page: 1,
          limit: 15,
          show_search_type: "0",
          view_search: [],
          order_by: {},
          scope_frame: "all",
          view_search_boolean: "",
          is_system: 1,
          is_field_all: 1
      }
      // end
    }
  },
  watch: {},

  created() {
    const routeString = this.$route.path
    const routeArray = routeString.split('/').filter((item) => item !== '')
    this.keyName = routeArray[3]
    this.getInfo()
  },
  // dengshunbo 2024-12-27新增
  mounted() {
      let loactionuserinfo = window.localStorage.getItem("userInfo")
      this.userinfoObj = JSON.parse(loactionuserinfo)

      if(this.keyName=="fangkeguanli"){
          this.getMenjinApi();
      }
  },
  // end
  destroyed() {
    this.$store.commit('updateConditionDialog', false)
  },

  methods: {
    getList() {
      this.loading = true
      crudModuleListApi(this.keyName, this.where)
        .then((res) => {
          this.loading = false
          this.total = res.data.count
          this.tableData = res.data.list
          setTimeout(() => {
            this.$refs.table?.doLayout()
          }, 300)
        })
        .catch((err) => {
          this.loading = false
        })
    },
    doLayout() {
      let that = this
    },
    openShare(row) {
      this.$refs.share.openBox(this.keyName, row)
    },
    cancelShare(val) {
      this.$modalSure('您确定要取消此数据的协作权限吗').then(() => {
        delCancelShareApi(this.keyName, val.id).then((res) => {
          this.getList()
        })
      })
    },
    handlecommendDropdowns(e){
      console.log("e", e)
    },
    handleDropdown(type, row) {
      this.dropdownType = type
      if (row) {
        this.rowData = row
      } else {
        this.rowData = {}
      }

      switch (type) {
        case 'transfer':
          // 移交
          if (this.multipleSelection.length == 0 && !row) return this.$message.error('请选择至少一项内容')
          this.fromData.title = '选择接手人'
          this.formConfig = [
            {
              type: 'user_id',
              label: '选择人员：',
              placeholder: '请选择人员（单选）',
              key: 'user_id',
              only_one: true,
              tips: '数据移交之后，以后由接手人负责；数据移交用于业务调整或者人员离职。'
            }
          ]
          this.$refs.oaDialog.openBox()
          break
        case 'share':
          // 共享
          if (this.multipleSelection.length == 0 && !row) return this.$message.error('请选择至少一项内容')
          this.fromData.title = '数据共享协作'
          this.formConfig = [
            {
              type: 'user_id',
              label: '选择人员：',
              placeholder: '请选择人员（多选）',
              key: 'user_ids',
              only_one: false
            },
            {
              type: 'select',
              label: '共享权限：',
              placeholder: '请选择共享权限',
              key: 'role_type',
              options: [
                { label: '仅可查看', value: '0' },
                { label: '可查看、编辑', value: '1' },
                { label: '可查看、编辑、删除', value: '2' }
              ]
            }
          ]
          this.$refs.oaDialog.openBox()
          break
        case 'fillIn':
          // 邀请填写
          this.$refs.fillInDialog.openBox(this.keyName)
          break
        case 'record':
          // 邀请记录
          this.$refs.fillIn.openBox(this.keyName)
          break
      }
    },
    submit(data) {
      let ids = []
      if (this.rowData.id) {
        ids.push(this.rowData.id)
      } else {
        this.multipleSelection.map((value) => {
          ids.push(value.id)
        })
      }

      if (this.dropdownType === 'transfer') {
        // 移交数据
        let obj = {
          ids,
          user_id: data.user_id[0]
        }
        moduleTransferApi(this.keyName, obj).then((res) => {
          if (res.status == 200) {
            this.$refs.oaDialog.handleClose()
            this.getList()
          }
        })
      } else if (this.dropdownType === 'share') {
        // 共享数据
        let obj = {
          ids,
          user_ids: data.user_ids,
          role_type: data.role_type
        }
        moduleShareApi(this.keyName, obj).then((res) => {
          if (res.status == 200) {
            this.$refs.oaDialog.handleClose()
            this.getList()
          }
        })
      }
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    // 数组转成字符串
    getValue(val, type) {
      let str = ''
      if (val == '') {
        str = '--'
      } else if (val && val.type) {
        str = val.name + `(${val.type})`
      } else if (type === 'input_select' && typeof val !== 'string') {
        if (val.type) {
          str = val.name + val.type ? '（' + val.type + '）' : ''
        } else {
          str = val.name
        }
      } else if (Array.isArray(val)) {
        str = val.toString()
      }else if(this.isImagePath(val)){ // dengshunbo 2024-12-27 新增图片路径判断
        str = 'image'
      } else {
        str = val
      }
      return str || '--'
    },
     // dengshunbo 2024-12-27 
     getValueStr(val){
        if(val.length > 55){
            return val.substring(0,55) + '...'
        }else{
           return val;
        }
     },
     // 判断字符串是否是图片路径
     isImagePath(path) {
       return /\.(jpg|jpeg|png|gif|webp)$/i.test(path);
    },
    handlerFilterAction(val){
      let actionarr = ["cheliangjinchujilu", "menjinjilu", "yunyingdingdanguanli", "chongdianzhuangguanli", "dianbiaoguanli", "shuibiaoguanli","xunjianguanli"]
      if(actionarr.includes(val)){
        return false;
      }else{
        return true;
      }
    },
    // 门禁组
    getMenjinApi(){
      crudModuleListApi('menjinzu', {page: 1, limit: 50})
        .then((res) => {
            this.menjinData = res.data.list;
        })
        .catch((err) => {
          this.loading = false
        })
    },
    handlerFiltermjz(val){
         if(val){
            let arrval = val.split(",")
            let selctData = []
            for(let i=0;i< this.menjinData.length;i++){
                if(arrval.includes(this.menjinData[i].menjinzuSN)){
                  selctData.push(this.menjinData[i].menjinzumingcheng)
                }
            }
            return selctData.join(",")
         }else{
            return ''
         }
    },
    handlerFiltermjzid(val){
         if(val && val.length > 0){
            let arrval = (val.split(",")).map(Number)
            let selctData = []
            for(let i=0;i< this.menjinData.length;i++){
                if(arrval.includes(this.menjinData[i].id)){
                  selctData.push(this.menjinData[i].menjinzumingcheng)
                }
            }
            return selctData.join(",")
         }else{
            return ''
         }
    },
    // 表格行点击事件
    async handleRowClick(row, column, event) {
      this.tableRowObject = row;
      this.currentRowIndex = row.id; // 假设每行有唯一id
      // this.checkNewDetailsShow = true
      // const data = await crudModuleFindApi(this.keyName, row.id)
      // let name = row[this.info.crudInfo.main_field_name] || '--'
      // setTimeout(() => {
      //   this.$nextTick(() => {
      //     this.$refs.checkNewDetails.openBox(row, data.data, this.info, name)
      //   })
      // }, 300)
    },
    // 双击表格行事件
    async handleRowDoubleClick(item, column, event) {
      const data = await crudModuleFindApi(this.keyName, item.id)
      if(this.keyName =='fangkeguanli'){
        this.addDrawerShow = true;
        this.$nextTick(() => {
          this.$refs.addDrawer.openBox(item.id, data.data)
        })
      }else if(this.keyName =='sunhaoshezhi'){
        this.addDrawerShowsunhao = true;
        this.$nextTick(() => {
          this.$refs.addsunhao.openBox(item.id, item)
        })
      }else{
        this.addDrawerShownew = true;
        this.$nextTick(() => {
          this.$refs.addDrawernew.openBox(item.id, data.data, 2)
        })
      }
    },
    tableRowClassName({row, rowIndex}) {
      if (row.id === this.currentRowIndex) {
        return 'highlight-row';
      }
      return '';
    },
    // end
    getColorFn(color, opacity) {
      return getColor(color, opacity)
    },

    handleDelete() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error('至少选择一项内容')
      } else {
        this.$modalSure('您确认要删除吗').then(() => {
          const ids = []
          this.multipleSelection.map((value) => {
            ids.push(value.id)
          })
          this.batchMessageDelete({ ids: ids })
        })
      }
    },

    // 批量删除
    batchMessageDelete(data) {
      crudModuleBatchDelApi(this.keyName, data).then((res) => {
        let totalPage = Math.ceil((this.total - data.ids.length) / this.where.limit)
        let currentPage = this.where.page > totalPage ? totalPage : this.where.page
        this.where.page = currentPage < 1 ? 1 : currentPage
        this.getList()
      })
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    // 新增-调用弹窗
    async addData(index=0) {
      console.log("index", index)
      // this.addDrawerShow = true
      if(this.keyName =='sunhaoshezhi'){
        this.addDrawerShowsunhao = true;
        this.$nextTick(() => {
          this.$refs.addsunhao.openBox()
        })
      }else{
        if(index==1){ // 复制
          if(this.tableRowObject){
             this.editRow(this.tableRowObject, 1)
          }else{
             this.$message.info("请选择一行数据再进行复制操作！")
          }
        }else if(index==11){ // 批核
            if(this.multipleSelection.length==1){
              if(this.multipleSelection[0].pihe==1){
                this.$message.error("该条数据已进行批核过，无法再次批核")
              }else{
                let selectobj = this.multipleSelection[0]; // 当前选择批核数据
                let tablename = 'xiaoshoumingxi'
                this.handlerUpdateTableBase(selectobj, 1, tablename)
              }
            }else if(this.multipleSelection.length > 1){
               this.$message.error("请一条一条数据进行批核")
            }else{
               this.$message.error("请选择要批核的数据！")
            }

        }else if(index==12){ // 反批核
          if(this.multipleSelection.length==1){
              if(this.multipleSelection[0].pihe !=1){
                this.$message.error("该条数据未进行批核无法反批核！")
              }else{
                let selectobj = this.multipleSelection[0]; // 当前选择批核数据
                let tablename = 'xiaoshoumingxi'
                this.handlerUpdateTableBase(selectobj, 0, tablename)
              }
           }else if(this.multipleSelection.length > 1){
            this.$message.error("请一条一条数据进行反批核")
           }else{
            this.$message.error("请选择要反批核的数据！")
           }
        }else{
          this.addDrawerShownew = true;
          this.$nextTick(() => {
            // this.$refs.addDrawer.openBox()
            this.$refs.addDrawernew.openBox()
          })
        }
      }
    },
    // 更新批核接口resdata更新的数据, id
    async handlerUpdateTableBase(selectobj, index, tablename){
      let searchform = this.searchObj; // 查询条件
      searchform.xiaoshoudingdanid = selectobj.id;
      let xiaoshoumingx = await crudModuleListApi(tablename, searchform) // 查看列表
      let xiaoshouData = xiaoshoumingx.data.list;
      let findData = await crudModuleFindApi(this.keyName,selectobj.id); // 查看详情
      let resdata = findData.data.module_info;
      let formdatas = resdata;
      formdatas.pihe = index;
      formdatas.piheren = ''
      formdatas.piheshijian = ''
      if(index==1){
        let daytimes = this.handlerDayTimes(); // 当前时间
        formdatas.piheshijian = daytimes
        formdatas.piheren = this.userinfoObj.name
      }
      this.handlerPiheChange(selectobj.id, formdatas, xiaoshouData, index, tablename);
    },
    // 订单批核接口
    async handlerPiheChange(id, formdata, list=[], index=0, tableName){
      crudModuleUpdateApi(this.keyName,id, formdata, true).then((res)=>{
          if(res.status == 200){
            this.$message.success(index == 1 ? "批核成功": "反批核成功");
            this.getList()
            if(list.length > 0){ // 批量更新子表批核状态
               for(let i=0;i<list.length;i++){
                  putUpdateFieldApi(tableName, list[i].id, { field_name: 'pihe', value: index }, true)
               }
            }
          }
      }).catch(err=>{
        this.$message.success("批核失败")
      })
    },
    async editRow(item, index=0) {
      // this.addDrawerShow = true
      const data = await crudModuleFindApi(this.keyName, item.id)
      if(this.keyName =='fangkeguanli'){
        this.addDrawerShow = true;
        this.$nextTick(() => {
          this.$refs.addDrawer.openBox(item.id, data.data)
        })
      }else if(this.keyName =='sunhaoshezhi'){
        this.addDrawerShowsunhao = true;
        this.$nextTick(() => {
          this.$refs.addsunhao.openBox(item.id, item)
        })
      }else{
        this.addDrawerShownew = true;
        this.$nextTick(() => {
          let resdatas = data.data || '';
          if(index==1 && resdatas){ // 复制
            if(resdatas.module_info.pihe==1){
               resdatas.module_info.pihe = 0;
               resdatas.module_info.piheren = ''
               resdatas.module_info.piheshijian = ''
            }
          }
          
          this.$refs.addDrawernew.openBox(item.id, resdatas, index)
        })
      }
    },

    async checkRow(item) {
      this.checkDrawerShow = true
      const data = await crudModuleFindApi(this.keyName, item.id)
      let name = item[this.info.crudInfo.main_field_name] || '--'

      setTimeout(() => {
        this.$nextTick(() => {
          this.$refs.checkDrawer.openBox(item, data.data, this.info, name)
        })
      }, 300)
    },

    async deleteRow(item) {
      await this.$modalSure('您确定要删除吗')
      await crudModuleDelApi(this.keyName, item.id)
      let totalPage = Math.ceil((this.total - 1) / this.where.limit)
      let currentPage = this.where.page > totalPage ? totalPage : this.where.page
      this.where.page = currentPage <= 1 ? 1 : currentPage
      await this.getList()
    },

    getInfo() {
      crudModuleInfoApi(this.keyName, 0).then((res) => {
        this.info = res.data
      })
    },

    // 查看与下载附件
    lookViewer(url, name = '') {
      this.srcList.push(url)
      this.$refs.imageViewer.openImageViewer(url)
    },

    confirmData(data) {
      if (data === 'import') {
        this.$refs.dragUpload.openBox(this.keyName, this.info)
      } else {
        this.where = { page: 1, limit: this.where.limit, ...data }
        this.getList()
      }
    },
    handleSizeChange(val) {
      this.where.limit = val
      this.getList()
    },
    pageChange(val) {
      this.where.page = val
      this.getList()
    },
    tabelWidth(item){
       let widthname = ['input_percentage','tag','textarea','date_picker','date_time_picker','cascader', 'cascader_address']
       let widthname2 = ['item_depc', 'gongsidaima']
       if(widthname.includes(item.form_value)){
          return '180'
       }else if(widthname2.includes(item.field_name_en)){
          return '220'
       }else if(item.field_name_en=='piheshijian'){
          return '160'
       }
       return ''
    },
    handlerSwitch(item, index){
       if(item == 'pihe'){
          return index==1 ? '已批核' : '未批核'
       }else{
          return index==1 ? '关闭' : '关闭'
       }
    },
    // 获取当前时间
    handlerDayTimes(){
      let date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      if (month < 10) {
        month = '0' + month;
      }
      if(day < 10){
         day = '0' + day;
      }
      let hours = date.getHours();
      let minuts = date.getMinutes();
      let scoends = date.getSeconds();
      return year + '-' + month + '-' + day + ' ' + hours + ':' + minuts + ':' + scoends;
    },
  }
}
</script>
<style scoped lang="scss">
// /deep/ .current-row {
//   background-color: #adffac;
// }
// /deep/ .el-table__body tr.current-row>td.el-table__cell{
//   background-color: #adffac;
// }
.img {
  cursor: pointer;
  display: block;
  width: 50px;
  height: 50px;
  margin-right: 4px;
  margin-bottom: 4px;
}
.share-tag {
  margin-left: 8px;
  display: inline-block;
  width: 36px;
  height: 22px;
  background: rgba(25, 190, 107, 0.05);
  color: #19be6b;
  border: 1px solid #19be6b;
  font-family: PingFang SC, PingFang SC;
  font-weight: 400;
  font-size: 12px;
  border-radius: 3px 3px 3px 3px;
  line-height: 22px;
  text-align: center;
}
.divBox{
  margin-top:0;
  padding-bottom:0;
}
.flex_box {
  width: 100%;
  padding-right: 10px;
  display: flex;

  .tips {
    span {
      margin-right: 4px;
    }
  }
}
.img-box {
  display: flex;
  flex-wrap: wrap;
}
.dictionaries-tag {
  max-width: 100px;
  display: inline-block;
  margin: 0;
  box-sizing: border-box;
  height: 24px;
  padding: 0 8px;
  text-align: center;
  line-height: 24px;
  font-size: 12px;
  border-radius: 3px;
}
.mr10 {
  margin-right: 10px !important;
}

.batch-action-wrapper {
  position: absolute;
  bottom: -11px;
  left: 0;
  right: 0;
  height: 82px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0px 1px 0px 0px rgba(0, 0, 0, 0.05);

  display: flex;
  align-items: center;
  padding-left: 54px;

  .el-checkbox {
    margin-right: 10px;
  }

  .el-button {
    width: 74px;
    height: 32px;
    padding: 0;

    &:focus {
      background: #fff;
      border: 1px solid #dcdfe6;
      color: #606266;
    }

    &:hover {
      color: #1890ff;
      border-color: #badeff;
      background-color: #e8f4ff;
    }
  }
}

.table-box {
  /deep/.el-table__column-resize-proxy {
    border-left-color: #6fbaff;
  }
  /deep/ .el-switch__core{
   min-width:66px;
}

  /deep/.el-table--border {
    border: none;
    .el-table__cell {
      border-right: none;
    }
  }

  /deep/.el-table__fixed-right .el-table__fixed-body-wrapper {
    border-right: 1px solid #fff;
  }
}
</style>
